package parsex

import (
	"encoding/json"
	"os"
)

func AnyToJson(data any, path string) error {
	marshal, err := json.Marshal(data)
	if err != nil {
		return err
	}
	err = os.WriteFile(path, marshal, 0644)
	if err != nil {
		return err
	}
	return nil
}

func JsonToAny[T any](data *T, path string) error {
	file, err := os.ReadFile(path)
	if err != nil {
		return err
	}
	err = json.Unmarshal(file, data)
	if err != nil {
		return err
	}
	return nil
}
